<!--
 * @Description: 
 * @Author: wind-lc
 * @version: 1.0
 * @Date: 2021-12-27 16:57:29
 * @LastEditTime: 2022-02-14 15:33:13
 * @FilePath: \cscec-pms-admin\src\components\BaseInput\index.vue
-->
<template>
  <a-tooltip :title="(localValue && localValue.length > showTipLength) ? localValue : ''">
    <div class="BaseInput-container">
      <a-input
        ref="aInput"
        v-model="localValue"
        :placeholder="disabled ? '' : placeholder"
        :max-length="maxLength"
        :disabled="disabled"
        v-bind="$attrs"
        v-on="$listeners"
        @input="change($event)"
      />
    </div>
  </a-tooltip>
</template>

<script>
export default {
  name: 'BaseInput',
  model: {
    event: 'packageInput'
  },
  props: {
    value: {
      type: [String, Number]
    },
    placeholder: {
      type: String,
      default: '请输入'
    },
    // 默认长度限制30
    maxLength: {
      type: Number,
      default: 100
    },
    // 默认显示tooltip长度
    showTipLength: {
      type: Number,
      default: 15
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    localValue: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('packageInput', val)
      }
    }
  },
  methods: {
    toBlur() {
      this.$refs.aInput.blur()
    },
    change(e) {
      this.$forceUpdate()
    },
  }
}
</script>

<style lang="less" scoped>
.BaseInput-container {
  position: relative;
}
</style>
